package han.chensing.latos.maker.latos.file.util;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import han.chensing.latos.common.level.LatosProject;

public class SerUtil {
    public static byte[] toBytes(LatosProject latosProject)
            throws Exception{
        ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream=new ObjectOutputStream(byteArrayOutputStream);
        objectOutputStream.writeObject(latosProject);
        byte[] bytes = byteArrayOutputStream.toByteArray();
        objectOutputStream.close();
        byteArrayOutputStream.close();
        return bytes;
    }

    public static LatosProject toObject(InputStream inputStream)
        throws Exception{
        ObjectInputStream objectInputStream=new ObjectInputStream(inputStream);
        LatosProject latosProject = (LatosProject) objectInputStream.readObject();
        objectInputStream.close();
        return latosProject;
    }
}
